package com.ts.main.admin.controller;

import com.ts.main.admin.context.UserContext;
import com.ts.main.admin.dto.AdminDto;
import com.ts.main.admin.dto.AdminLoginDto;
import com.ts.main.admin.dto.AdminSearchPageDto;
import com.ts.main.admin.exception.R;
import com.ts.main.admin.exception.RPage;
import com.ts.main.admin.service.AdminServiceImpl;
import com.ts.main.admin.vo.AdminVo;
import com.ts.main.admin.vo.AdminRolePartVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:lk
 * @Date: 2025/6/9  00:54
 */
@AllArgsConstructor
@RestController
@RequestMapping("/user")
@Tag(name = "系统设置-用户管理")
public class AdminController {

    private final AdminServiceImpl adminService;

    @GetMapping("/getUserInfo")
    @Operation(summary = "查询当前用户信息")
    public R<AdminVo> getAdminInfo(){
        return R.ok(UserContext.getUser());
    }

    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public R<AdminVo> login(@RequestBody AdminLoginDto dto) {
        return R.ok(adminService.login(dto));
    }

    @PutMapping("/resetPassword")
    @Operation(summary = "重置密码")
    public R resetPassword(@Schema(description = "用户ID") @RequestParam Integer id) {
        return R.ok(adminService.resetPassword(id));
    }

    @PostMapping("/saveUser")
    @Operation(summary = "添加用户")
    public R<AdminDto> saveUser(@RequestBody AdminDto dto){
        return R.ok(adminService.saveUser(dto));
    }

    @PutMapping("/updateUser")
    @Operation(summary = "修改用户")
    public R<Boolean> updateUser(@RequestBody AdminDto dto){
        return R.ok(adminService.updateUser(dto));
    }

    @DeleteMapping("/deleteUser")
    @Operation(summary = "删除用户")
    public R deleteUser(@Schema(description = "用户ID") @RequestParam Integer id){
        return R.ok(adminService.deleteUser(id));
    }

    @PostMapping("/getUserList")
    @Operation(summary = "查询用户列表")
    public RPage<List<AdminVo>> getUserList(@RequestBody AdminSearchPageDto dto){
        return adminService.getUserList(dto);
    }

    @GetMapping("/getUserDetails")
    @Operation(summary = "查询用户详情")
    public R<AdminVo> getUserDetails(@Schema(description = "用户ID") @RequestParam Integer id){
        return R.ok(adminService.getUserDetails(id));
    }

    @GetMapping("/getRoleList")
    @Operation(summary = "查询角色列表")
    public R<List<AdminRolePartVo>> getRoleList(){
        return R.ok(adminService.getRoleList());
    }

}
